#!/usr/bin/env python


def options(opt):
	opt.add_option('--disable-pxp', action = 'store_true', default = False, help = 'disable PXP plugin [default: enabled]')


def configure(conf):
	if conf.options.disable_pxp:
		return

	if not conf.env['WITH_GSTVIDEO']:
		return

	from waflib.Build import Logs
	if conf.check_cc(fragment = '''
		#include <linux/pxp_device.h>

		int main() { return 0; }
		''',
		uselib_store = 'IMXPXP',
		uselib = 'KERNEL_HEADERS',
		mandatory = False,
		execute = False,
		msg = 'checking for linux/pxp_device.h'
	):
		Logs.pprint('GREEN', 'PxP elements will be built')
		conf.env['PXP_ELEMENTS_ENABLED'] = 1
	else:
		Logs.pprint('RED', 'PxP elements will not be built - headers not found')


def build(bld):
	if bld.env['PXP_ELEMENTS_ENABLED']:
		bld(
			features = ['c', bld.env['CLIBTYPE']],
			includes = ['.', '../..'],
			uselib = bld.env['COMMON_USELIB'] + ['IMXPXP', 'KERNEL_HEADERS'],
			use = ['gstimxcommon', 'gstimxblitter', 'gstimxcompositor'],
			target = 'gstimxpxp',
			source = bld.path.ant_glob('*.c'),
			install_path = bld.env['PLUGIN_INSTALL_PATH']
		)
